piclist 1997\07\18\090751a
>
Thread:
Multitasking
www.piclist.org/techref/microchip/ints.htm?key=multitasking
BY
:
Dmitry Kiryashov email (remove spam text)
Hello Clyde !
> On Fri, Jul 18, 1997 at 02:24:07PM +0300, KORKMAZ SAiT ULAS wrote:
> > Is there a way to read the stack . I am designing a multitasking
>
> The short answer is "no".
>
> > Does anybody know a technique to do this ?
>
> It's impossible on a PIC - the only thing you can do with the
> stack is use it for call/return. If you want to do true
> multi-tasking, the PIC is not for you.
The long answer is yes ! ;) But it will be software implemented stack.
Let we reserve some byte array STACK[] , about 4 bytes for example.
So we can store 2 procedure addresses - Proc_1 and Proc_2 .
STACK[0] = HIGH ( Proc_1 ) ; STACK[1] = LOW ( Proc_1 ) ;
STACK[2] = HIGH ( Proc_2 ) ; STACK[3] = LOW ( Proc_2 ) ;
And we have some piece of code (SEMAPHORE) with one byte pointer
(POINTER),
which point to position in STACK[] of next called address . If we wish
to call
Proc_1 than POINTER=0 , in case of Proc_2 POINTER=2 etc. Certainly in
multitasker
we should also have additional flags , but i don't discuss about it .
(For example
flags that indicate what task is active/down/... ) POINTER var is useful
to know
what last Proc_ was called .
Finally, to call Proc_1 we do foolowing :
; First we should initialize STACK[] array
MOVLW HIGH Proc_1
MOVWF STACK
MOVLW LOW Proc_1
MOVWF STACK+1
....
; Main part - CALL Proc_1
MOVLW 0
CALL SEMAPHORE ;CALL Proc_1
; CALL Proc_2
MOVLW 2
CALL SEMAPHORE ;CALL Proc_2
SEMAPHORE:
MOVWF POINTER
ADDLW STACK
MOVWF FSR
MOVFW INDF
MOVWF PCLATH
INCF FSR
MOVFW INDF
MOVWF PCL ; It's hidden GOTO ;)
; There are ability to save PCLATH and any another registers if need
; before GOTO to called Proc_ .
Proc_1:
...
...
RETURN
Proc_2:
...
...
RETURN
That's all . I was thinking this idea to make multitasking with PIC ,
but I still haven't time to do it ;(((
WBR Dmitry.
P.S. I have interest to look any theoretical/practical ideas in this
area .
<33CF6779.174C@aha.ru> 7bit
See also: www.piclist.org/techref/microchip/ints.htm?key=multitasking
Reply
You must be a member of the
piclist mailing list
(not only a www.piclist.org member) to post to the
piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
month overview.
new search...